{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from matplotlib import pyplot as plt\n",
    "from ipywidgets import interact"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "fname = '../input/home-credit-default-risk-publicleaderboard.csv'\n",
    "TeamName = 'ONODERA'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(fname, parse_dates=['SubmissionDate'])\n",
    "\n",
    "\n",
    "dates = pd.date_range(df.SubmissionDate.min(), df.SubmissionDate.max(), \n",
    "              freq='H')\n",
    "\n",
    "#d_min, d_max = min(dates), max(dates)\n",
    "\n",
    "#df2 = df[df.SubmissionDate.between(d_min, d_max)]\n",
    "\n",
    "df.sort_values('SubmissionDate', ascending=False, inplace=True)\n",
    "\n",
    "s_min, s_max = df.Score.min(), df.Score.max()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "91c5296a5aed452cb36aafcd75cf078e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "A Jupyter Widget"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(n=(5, len(dates)-1))\n",
    "def plot_LB(n):\n",
    "    d = dates[n]\n",
    "    df2 = df[df.SubmissionDate<d].drop_duplicates('TeamId', keep='first')\n",
    "    df2.Score.plot(kind='hist', bins=200)\n",
    "    plt.xlim(0.7, s_max)\n",
    "    plt.ylim(0., 400)\n",
    "    plt.title(d)\n",
    "    try:\n",
    "        plt.annotate('me', xy=(df2.loc[df2.TeamName==TeamName, 'Score'].values[0], 0),\n",
    "                     arrowprops=dict(shrink=0.1))\n",
    "    except:\n",
    "        pass\n",
    "    plt.show()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
